<?php
/**
 * Created by PhpStorm.
 * User: HS032
 * Date: 2020/9/14
 * Time: 10:03
 */

namespace ticket\modules\backend\controllers;


use ticket\libs\Tools;
use ticket\modules\backend\models\TicketCode;

class TicketCodeController extends BasicController
{

    public function actionCodeList()
    {
        $get = \Yii::$app->request->get();
        $ticketCodeModel = new TicketCode();
        $data = $ticketCodeModel->list($this->appId,$get);
        return Tools::showRes(0,'success',$data);

    }


    public function actionAddCode()
    {
        if (\Yii::$app->request->isPost){
            $post = \Yii::$app->request->post();
            $ticketCodeModel = new TicketCode();
            if (!$ticketCodeModel->addInfo($this->appId,$post)){
                if ($ticketCodeModel->hasErrors()){
                    return Tools::showRes(10405,$ticketCodeModel->getErrors());
                }else{
                    return Tools::showRes(10406,'添加失败');
                }
            }

            return Tools::showRes(0,'success');

        }
    }


    public function actionModCode()
    {
        if (\Yii::$app->request->isPost){
            $post = \Yii::$app->request->post();
            $id = isset($post['id'])?$post['id']:'';
            $ticketCodeModel = new TicketCode();
            if (!$ticketCodeModel->modInfo($id,$post)){
                if ($ticketCodeModel->hasErrors()){
                    return Tools::showRes(10405,$ticketCodeModel->getErrors());
                }else{
                    return Tools::showRes(10406,'修改失败');
                }
            }

            return Tools::showRes(0,'success');

        }
    }

    public function actionDelCode()
    {
        if (\Yii::$app->request->isPost){
            $post = \Yii::$app->request->post();
            $id = isset($post['id'])?$post['id']:'';
            $ticketCodeModel = new TicketCode();
            if (!$ticketCodeModel->delInfo($this->appId,$id)){
                return Tools::showRes(10406,'删除失败');
            }
            return Tools::showRes(0,'success');

        }
    }
    
    
    
    
    
}